<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>添加课程</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../static/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../static/css/admin.css" media="all">
</head>
<body>
<div class="layui-container">
    <form id="myform" class="layui-form" lay-filter="layuiadmin-form-admin" id="layuiadmin-form-admin" style="padding: 20px 30px 0 0;">
        <input type="hidden" name="id">
        <!--姓名-->
        <div class="layui-form-item">
            <label class="layui-form-label required">课程名</label>
            <div class="layui-input-inline">
                <input type="text" name="courseName" id="courseName" lay-verify="required" placeholder="请输课程名" autocomplete="off" class="layui-input">
            </div>
        </div>

        <!--教练名-->
        <div class="layui-form-item">
            <label class="layui-form-label required">课程教练</label>
            <div class="layui-input-inline">
                <input type="text" name="courseCoach"  id="courseCoach" lay-verify="required" placeholder="请输入课程教练" autocomplete="off" class="layui-input">
            </div>
        </div>

        <!--课程时长-->
        <div class="layui-form-item">
            <label class="layui-form-label">课程时长</label>
            <div class="layui-input-inline">
                <input type="text" name="courseTime" id="courseTime" class="layui-input" placeholder="请输入课程时长">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">课程容量</label>
            <div class="layui-input-inline">
                <input type="text" name="courseCount" id="courseCount" class="layui-input" placeholder="请输入课程容量">
            </div>
        </div><div class="layui-form-item">
        <label class="layui-form-label">已报人数</label>
        <div class="layui-input-inline">
            <input type="text" name="courseAlready" id="courseAlready" class="layui-input" placeholder="请输入已报人数">
        </div>


        <!--确认提交-->
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="submit" class="layui-btn" lay-submit lay-filter="LAY-user-front-submit" id="LAY-user-back-submit">添加课程</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>

<!--引入本地layui.js-->
<script src="../static/layui/layui.js"></script>
<!--js-->
<script type="text/javascript">
    layui.config({
        base: '../static/layui/layuiadmin/' //静态资源所在路径js
    }).extend({
        index: 'lib/index' //主入口模块
    }).use('index');
</script>

<!--表单验证和调用接口传参-->
<script>
    layui.use(['form', 'layedit', 'laydate','layer'], function(){
        var form = layui.form
            ,layer = layui.layer
            ,layedit = layui.layedit
            ,laydate = layui.laydate;

        form.on('submit',function (data) {
            let courseName = $("input[name='courseName']").val();
            let courseCoach = $("input[name='courseCoach']").val();
            let courseTime = $("input[name='courseTime']").val();
            let courseCount = $("input[name='courseCount']").val();
            let courseAlready = $("input[name='courseAlready']").val();
            $.ajax({
                type: "post",
                url: "http://localhost:8181/course/insertCourse",
                data: JSON.stringify(data.field),
                dataType: "json",
                contentType:'application/json',
                success: function (res) {
                    if(res.code == 200){//code=200登录成功
                        //1.弹出提示信息
                        layer.msg('添加成功',{
                            offset:'15px',
                            icon:1,
                            time:1000
                        },function () {
                            window.parent.location.reload();
                        });
                    }else {
                        layer.msg('添加失败',{
                            offset:'15px',
                            icon:1,
                            time:1000
                        },function () {

                            window.location.href = "accountAdd.html"
                        });
                    }
                }
            })
            return false;
        })
        /*:form.on()表单监控事件中一定要加 return false;
        如果不加的话,后端不会报错,而前端代码中不会运行到success中,
        不同浏览器也有不同效果,谷歌浏览器有时会报错,火狐和其他浏览器100%报错*/

    })
    //Demo


</script>
<script src="../static/js/jquery-3.6.0.min.js"></script>
</body>
</html>